package com.crm.service.impl.csd.customerManager;

import com.crm.dao.mapper.contactManager.ContactInformationMapper;
import com.crm.dao.mapper.contactManager.ContactMapper;
import com.crm.dao.mapper.customMapper.csd.ContactMaintainMapper;
import com.crm.dao.mapper.customerManager.CustomerContactPersonMapper;
import com.crm.dao.mapper.customerManager.CustomerMapper;
import com.crm.model.entity.contactManager.Contact;
import com.crm.model.entity.contactManager.ContactInformation;
import com.crm.model.entity.contactManager.ContactInformationExample;
import com.crm.model.entity.customerManager.Customer;
import com.crm.model.entity.customerManager.CustomerContactPerson;
import com.crm.model.entity.customerManager.CustomerContactPersonExample;
import com.crm.model.qo.csd.customerManager.ContactMaintainQO;
import com.crm.model.vo.csd.customerManager.ContactMaintainVO;
import com.crm.service.csd.customerManager.ContactMaintainDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yincuimei
 * @Date 2021/10/25 15:26
 */
@Service
public class ContactMaintainDbServiceImpl implements ContactMaintainDbService {
    @Autowired
    private ContactMaintainMapper contactMaintainMapper;
    @Autowired
    private ContactMapper contactMapper;
    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private ContactInformationMapper contactInformationMapper;
    @Autowired
    private CustomerContactPersonMapper customerContactPersonMapper;

    /**
     * (客服部)》联系人管理-》联系人维护列表
     * @param contactMaintainQO --查询条件
     * @param orderStr          --排序
     * @author yincuimei
     * @return
     */
    @Override
    public List<ContactMaintainVO> selectContactMaintainVOList(ContactMaintainQO contactMaintainQO, String orderStr) {
        return contactMaintainMapper.selectContactMaintainVOList(contactMaintainQO,orderStr);
    }

    /**
     * 联系人维护-》批量审核
     * @param contactIds --联系人ID集合
     * @param contact    --联系人实体(更新时间、更新人、审核信息)
     * @author yincuimei
     * @return
     */
    @Override
    public Boolean updateExamineByIdsBatch(List contactIds, Contact contact) {
        return contactMaintainMapper.updateExamineByIdsBatch(contactIds,contact) > 0;
    }

    /**
     * 联系人维护-》批量审核-通过联系人ID集合查询联系人集合
     * @param contactIds
     * @author yincuimei
     * @return
     */
    @Override
    public List<Contact> selectContactListByIds(List<String> contactIds) {
        return contactMaintainMapper.selectContactListByIds(contactIds);
    }

    /**
     * 联系人维护-》删除(删除联系人表:lxr_contact)
     * @param contact
     * @author yincuimei
     * @return
     */
    @Override
    public Boolean deleteContactByContactId(Contact contact) {
        return contactMapper.updateByPrimaryKeySelective(contact) > 0;
    }

    /**
     * 联系人维护-》删除(删除联系方式表:lxr_contact_information)
     * @param contactInformation
     * @describe : 联系方式表存联系人表contact_id,contact_id和联系方式表位一对多关系
     * @author yincuimei
     * @return
     */
    @Override
    public Boolean deleteContactInformationByContactId(ContactInformation contactInformation, ContactInformationExample example) {
        return contactInformationMapper.updateByExampleSelective(contactInformation,example) > 0;
    }

    /**
     * 联系人维护-》删除(个人联系人-删除客户表相关数据:chs_customer)
     * @param customer
     * @describe : 关联关系->联系人表存客户表ID
     * @author yincuimei
     * @return
     */
    @Override
    public Boolean deleteCustomerByCustomerId(Customer customer) {
        return customerMapper.updateByPrimaryKeySelective(customer) > 0;
    }

    /**
     * 联系人维护-》删除(企业联系人-删除客户联系人表相关数据:chs_customer_contact_person)
     * @param customerContactPerson
     * @param example
     * @describe : 关联关系->客户联系人表存客户表ID
     * @author yincuimei
     * @return
     */
    @Override
    public Boolean deleteCustomerContactPersonByCustomerId(CustomerContactPerson customerContactPerson, CustomerContactPersonExample example) {
        return customerContactPersonMapper.updateByExampleSelective(customerContactPerson,example) > 0;
    }
}
